/*     */ package com.zimbra.cs.account.ldap;
/*     */ 
/*     */ import com.zimbra.common.mailbox.ContactConstants;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.StringUtil;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Entry;
/*     */ import com.zimbra.cs.account.grouphandler.GroupHandler;
/*     */ import com.zimbra.cs.ldap.IAttributes;
/*     */ import com.zimbra.cs.ldap.ILdapContext;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.HashSet;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Set;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class LdapGalMapRules
/*     */ {
/*     */   private List<LdapGalMapRule> mRules;
/*     */   private List<String> mLdapAttrs;
/*     */   private Set<String> mBinaryLdapAttrs;
/*     */   private Map<String, LdapGalValueMap> mValueMaps;
/*     */   private GroupHandler mGroupHandler;
/*     */   private boolean mFetchGroupMembers;
/*     */   private boolean mNeedSMIMECerts;
/*     */   private static final String OLD_DEFAULT_GROUPHANDLER = "com.zimbra.cs.gal.ADGalGroupHandler";
/*     */   private static final String CURRENT_DEFAULT_GROUPHANDLER = "com.zimbra.cs.account.grouphandler.ADGroupHandler";
/*     */   
/*     */   public LdapGalMapRules(String[] rules, String[] valueMaps, String groupHandlerClass)
/*     */   {
/*  55 */     init(rules, valueMaps, groupHandlerClass);
/*     */   }
/*     */   
/*     */   public LdapGalMapRules(Config config, boolean isZimbraGal) {
/*  59 */     init(config, isZimbraGal);
/*     */   }
/*     */   
/*     */   public LdapGalMapRules(Domain domain, boolean isZimbraGal) {
/*  63 */     init(domain, isZimbraGal);
/*     */   }
/*     */   
/*     */   private void init(Entry entry, boolean isZimbraGal) {
/*  67 */     String groupHanlderClass = null;
/*  68 */     if (!isZimbraGal) {
/*  69 */       groupHanlderClass = entry.getAttr("zimbraGalLdapGroupHandlerClass");
/*     */     }
/*  71 */     init(entry.getMultiAttr("zimbraGalLdapAttrMap"), entry.getMultiAttr("zimbraGalLdapValueMap"), groupHanlderClass);
/*     */   }
/*     */   
/*     */ 
/*     */   private void init(String[] rules, String[] valueMaps, String groupHandlerClass)
/*     */   {
/*  77 */     if (valueMaps != null) {
/*  78 */       this.mValueMaps = new HashMap(valueMaps.length);
/*  79 */       for (String valueMap : valueMaps) {
/*  80 */         LdapGalValueMap vMap = new LdapGalValueMap(valueMap);
/*  81 */         this.mValueMaps.put(vMap.getFieldName(), vMap);
/*     */       }
/*     */     }
/*     */     
/*  85 */     this.mRules = new ArrayList(rules.length);
/*  86 */     this.mLdapAttrs = new ArrayList();
/*  87 */     this.mBinaryLdapAttrs = new HashSet();
/*  88 */     for (String rule : rules) {
/*  89 */       add(rule);
/*     */     }
/*  91 */     if (StringUtil.equal(groupHandlerClass, "com.zimbra.cs.gal.ADGalGroupHandler")) {
/*  92 */       groupHandlerClass = "com.zimbra.cs.account.grouphandler.ADGroupHandler";
/*     */     }
/*  94 */     this.mGroupHandler = GroupHandler.getHandler(groupHandlerClass);
/*  95 */     ZimbraLog.gal.debug("groupHandlerClass=" + groupHandlerClass + ", handler instantiated=" + this.mGroupHandler.getClass().getCanonicalName());
/*     */   }
/*     */   
/*     */   public void setFetchGroupMembers(boolean fetchGroupMembers) {
/*  99 */     this.mFetchGroupMembers = fetchGroupMembers;
/*     */   }
/*     */   
/*     */   public void setNeedSMIMECerts(boolean needSMIMECerts) {
/* 103 */     this.mNeedSMIMECerts = needSMIMECerts;
/*     */   }
/*     */   
/*     */   public String[] getLdapAttrs() {
/* 107 */     return (String[])this.mLdapAttrs.toArray(new String[this.mLdapAttrs.size()]);
/*     */   }
/*     */   
/*     */   public Set<String> getBinaryLdapAttrs()
/*     */   {
/* 112 */     return this.mBinaryLdapAttrs;
/*     */   }
/*     */   
/*     */   public Map<String, Object> apply(ILdapContext ldapContext, String searchBase, String entryDN, IAttributes ldapAttrs)
/*     */   {
/* 117 */     HashMap<String, Object> contactAttrs = new HashMap();
/* 118 */     for (LdapGalMapRule rule : this.mRules) {
/* 119 */       if ((this.mNeedSMIMECerts) || (!rule.isSMIMECertificate()))
/*     */       {
/*     */ 
/* 122 */         rule.apply(ldapAttrs, contactAttrs);
/*     */       }
/*     */     }
/* 125 */     if (this.mGroupHandler.isGroup(ldapAttrs)) {
/*     */       try {
/* 127 */         if (this.mFetchGroupMembers) {
/* 128 */           contactAttrs.put(ContactConstants.A_member, this.mGroupHandler.getMembers(ldapContext, searchBase, entryDN, ldapAttrs));
/*     */         }
/*     */         else
/*     */         {
/* 132 */           contactAttrs.remove(ContactConstants.A_member);
/*     */         }
/* 134 */         contactAttrs.put(ContactConstants.A_type, "group");
/*     */       } catch (ServiceException e) {
/* 136 */         ZimbraLog.gal.warn("unable to retrieve group members ", e);
/*     */       }
/*     */     }
/*     */     
/* 140 */     return contactAttrs;
/*     */   }
/*     */   
/*     */   public void add(String rule) {
/* 144 */     LdapGalMapRule lgmr = new LdapGalMapRule(rule, this.mValueMaps);
/* 145 */     this.mRules.add(lgmr);
/* 146 */     for (String ldapattr : lgmr.getLdapAttrs()) {
/* 147 */       this.mLdapAttrs.add(ldapattr);
/*     */       
/* 149 */       if (lgmr.isBinary()) {
/* 150 */         this.mBinaryLdapAttrs.add(ldapattr);
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/account/ldap/LdapGalMapRules.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */